#ifndef __BIBOFRAME_SCENE_B__
#define __BIBOFRAME_SCENE_B__
#include "Box2D.h"
#include "cocos2d.h"
#include "CCMySprite.h"
#include "SimpleAudioEngine.h"
class BiboFrame : public cocos2d::CCLayer
{
public:
	// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
	virtual bool init();  

	// there's no 'id' in cpp, so we recommend returning the class instance pointer
	static cocos2d::CCScene* scene();

	// a selector callback
	void menuCloseCallback(CCObject* pSender);

	// implement the "static node()" method manually
	CREATE_FUNC(BiboFrame);
	// vo trong hieu
	static CCMySprite *background;
    static CCMySprite *selectingSprite;
	static cocos2d::CCSize winSize;
	//cocos2d::CCPoint originalPosition;
	cocos2d::CCPoint currentTouchingLocation,previousTouchingLocation;
	static cocos2d::CCArray *equipmentArray,*antiObjectsArray,*sprites,*m4aEffectListFile,*spriteChildNeedUpdateLifeTimeArray,*soundIDsLoopArr;
	int currentIdSequence;
	//cocos2d::CCDictionary *mainDict;
	cocos2d::CCPoint originalPosition;
	int soundEffectIDWithLoop;
	static int previousKeyStateCode;

	bool flag;
	bool isAlreadyInit;

	int idAptMin, idAptMax;

	cocos2d::CCPoint pointTemp;
	static cocos2d::CCLabelTTF *recordLabel;
	int record;
	//SOUND FFECT
	int currentFXSoundID;
	//CDLongAudioSource *rightChannel;
	//ALuint soundEffectID;
	//CDSoundSource *movSoundEffect;
	//CDSoundSource *movSoundEffect;


	///PARTICLE EFFECTS
	cocos2d::CCParticleSystem *emitter;
	///
	cocos2d::CCRect textureAlphabet;
	cocos2d::CCPoint choosenAlphabetImageLocation;
	//
	int totalTrackingPoint;
	//OPENING SOUND EFFECT
	//SimpleAudioEngine *openingSoundEffect;
	//amount of time user trace an alphabet
	static float realCurrentSecond,timeTracing;
	/////SCAL PERCENT::REAL IMAGE SIZE VS REAL DEVICE SIZE
	static float scalePercentX,scalePercentY,numCountBySecond;
	//box2d	
	b2World* world;
	b2Body* groundBody;
	b2MouseJoint *_mouseJoint;
	b2Body *_curBody;

	//GLESDebugDraw *m_debugDraw;	
    cocos2d::CCPoint _previousPosition;

	///methods
	static cocos2d::CCArray* componentsSeparatedByString(string _string, const char *delimiter);
	cocos2d::CCPoint getRandomPoint(float left, float right, float top, float bot);
	void removeAnArrayOfChild(cocos2d::CCArray* tmpArray);
	cocos2d::CCDictionary* getDictionaryOfSprite(cocos2d::CCString* sPlistName,cocos2d::CCString* dictName);
	void doParticleFire(float fDuration,int totalParts,float fSpeed,cocos2d::CCString* img,cocos2d::CCPoint loca);
	void doParticleFireEffect(float fDuration,int totalParts,float fSpeed,cocos2d::CCString* img,cocos2d::CCPoint loca);
	cocos2d::CCString* readPlistFile(cocos2d::CCString* sPlistName,cocos2d::CCString* dictName);
	void addParticleFlower(cocos2d::CCString* imageNameFile,float fDuration,int nTotalParticles,float fSpeed,cocos2d::CCPoint loc);
	float getDistanceTwoPoint(cocos2d::CCPoint p1,cocos2d::CCPoint p2);
	void doParticleFireWork(cocos2d::CCPoint loca,cocos2d::CCString* img,int amount);
	void doParticleFireEffect(cocos2d::CCPoint loca,cocos2d::CCString* img,int amountParts,float fSpeed);
	void doParticleEffect(cocos2d::CCObject* ob,cocos2d::CCPoint loca,cocos2d::CCString* img,int amountParts,int order);
	static cocos2d::CCArray* searchForChildrenByTag(int ident, cocos2d::CCArray* children);
	static cocos2d::CCArray* searchForChildrenByTag(cocos2d::CCArray *idArray, cocos2d::CCArray* children);
	static cocos2d::CCArray* searchForSpritesById(int ident, cocos2d::CCArray* array);
	static CCMySprite* searchForSpriteById(int ident,cocos2d::CCArray* tmpArray);
	static cocos2d::CCPoint calPosition(CCMySprite* sprite,cocos2d::CCPoint designViewPosition);
	static void playSoundFXFor(int type);
	static void selectSpriteForTouch(cocos2d::CCPoint touchLocation, cocos2d::CCArray* array);
    static void selectChildForTouch(cocos2d::CCPoint touchLocation, cocos2d::CCArray* children);
	static int getRandomNum(int max,int min);
	void setAlphabet(cocos2d::CCString* apb);
	cocos2d::CCScene* scene(cocos2d::CCString* ids);
	void showAlphabetSetNearAlphabetID(int zOrder);
	void doShakingEffect(CCMySprite* sp,float iDuration,float fAngle,int iTimes);
	void doUpDownEffect(CCMySprite* sp,cocos2d::CCTime iDuration,int distanceUp,int distanceDown,int iTimes);
	void doLeftRightEffect(CCMySprite* sp,cocos2d::CCTime iDuration,int distanceLeft,int distanceRight,int iTimes);
	static void initSpriteArrWithDir1(cocos2d::CCArray* tmpArray, string plistName);
	//void touchBeganAPT1(UITouch* touch withEvent,UIEvent * event);
	//void configSpriteArrWithDir2(cocos2d::CCString *)path;
	static void configSpriteArrWithDir1(cocos2d::CCString * path);
	virtual void updateShowingInitScreen(float dt);
	void doTransparentTrackingPoints();
	int rankTracing();
	void writeRankResult(int rank);
	bool isTouchingLeftToRight(cocos2d::CCPoint p1,cocos2d::CCPoint p2);
	//void panForTranslation(cocos2d::CCPoint translation);
	void turnToPreTracingScene();
	void turnScene(cocos2d::CCString* _i);
	void readData();
	//void movedTouchActions(CCMovableSprite * spr ,UITouch*  touch ,cocos2d::CCPoint touchLocation);
	void playSoundEffectWithLoop(cocos2d::CCTime dt);
	static cocos2d::CCArray* shareStaticArray();
	//void ccTouchEnded(UITouch *)touch withEvent,UIEvent *)event;
	//bool ccTouchBegan(UITouch *)touch withEvent,UIEvent *)event;
	//void ccTouchMoved(UITouch *)touch withEvent,UIEvent *)event;
	//void showHideSprite;
	//cocos2d::CCPoint generatePoint(int x,int y width,int)width height,int)height;
	//CGFloat calMoveDuration(cocos2d::CCPoint)newPosition ,cocos2d::CCPoint)curPosition ,float)velocity;
	//void showHelp;
	static void doScaleEffect(CCMySprite* sp ,float iDruration ,float scaleNumX ,float scaleNumY ,int iTimes);
	static void doRotate360Effect(CCMySprite* sp,float iDuration,int iTimes);
	static void doRotate360Effect(CCMySprite* sp,float iDuration);
	void doJumpingEffect(CCMySprite* sp,cocos2d::CCTime iDuration,cocos2d::CCPoint loc,cocos2d::CCTime iHeight,int iJumps,int iTimes);
	void initPhysics();
	void addASoundIDintoSoundIdsLoopArr(cocos2d::CCString* sID);
	void removeASoundIDFromSoundIDsArr(cocos2d::CCString* sID);
	static CCMySprite* duplicatteASprite(CCMySprite* sp1);
	static cocos2d::CCArray* generatePlayerLives(int liveSpriteID, int total);
	~BiboFrame();
	BiboFrame();
	void removeAllChildrenOutOfScreen();
	void spriteFinished(cocos2d::CCNode* sender);
    
    virtual void ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent *event);
    virtual void ccTouchesMoved(cocos2d::CCSet* touches, cocos2d::CCEvent *event);
    virtual void ccTouchesEnded(cocos2d::CCSet * touches, cocos2d::CCEvent *event);
    void panForTranslation(cocos2d::CCPoint translation) ;
};
#endif // __BIBOFRAME_SCENE_B__
